﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SAMPRO.Web.GFC;
using System.Web.Security;

public partial class Login_GFC : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        string gfcSiteAuthId = (string)Application["gfcSiteAuthId"];
        if (HttpContext.Current.User.Identity.IsAuthenticated == true)
        {
            //User is already logged in with YourSite Id.
            //log the user out first from YourSite account.
            if (Session["isFriendConnect"] != null && (Boolean)Session["isFriendConnect"] != true)
            {
                //FormsAuthentication.SignOut();
            }
        }

        string fcAuthToken = string.Empty;
        gfcUser g_user = null;
        
        //Replace #################### with SiteId from GFC
        //if (Request.Cookies["fcauth####################"] != null)
        if (Request.Cookies[gfcSiteAuthId] != null)
        {
            //Replace #################### with SiteId from GFC
            //fcAuthToken = Request.Cookies["fcauth####################"].Value;
            fcAuthToken = Request.Cookies[gfcSiteAuthId].Value;
            Session["fcAuthToken"] = fcAuthToken;
            g_user = FriendConnectUtil.getViewer(fcAuthToken);
            Session["isFriendConnect"] = true;

            //Membership.FindUsersByName("");
            //MembershipUser usr = 
            //    MembershipEx.GetGfcUser(g_user.gfcId, true);

            //Membership.CreateUser(
            //FormsAuthentication.SetAuthCookie(usr.UserName, true);
        }
        else
        {
            Session["fcAuthToken"] = "";
            Session["isFriendConnect"] = false;
        }
        Response.Redirect("~/default.aspx");
    }
}
